package homework;

public class Triangle {
    private double a;
    private double b;
    private double c;

    public double getA() {
        return a;
    }

    public void setA(double a) {
        this.a = a;
    }

    public double getB() {
        return b;
    }

    public void setB(double b) {
        this.b = b;
    }

    public double getC() {
        return c;
    }

    public void setC(double c) {
        this.c = c;
    }
    public void setBases(double a, double b, double c){
        if (a <= 0 || b <= 0 || c <= 0) {
            System.out.println("三角形的边长必须是正数");
            return;
        }

        if (a + b <= c || a + c <= b || b + c <= a) {
            System.out.println("三角形的任意两边之和必须大于第三边");
            return;

        }
        this.a = a;
        this.b = b;
        this.c = c;
    }

    public double area(){
        double s = (a + b + c) / 2;
        return Math.sqrt(s * (s - a) * (s - b) * (s - c));
    }
    public double perimeter(){
        return a+b+c;
    }
    public String getInfo(){
        return "三角形的三边分别为"+a+"、"+b+"、"+c+",面积为"+area()+"，周长为"+perimeter();
    }
}
